import { Table, Column, Model } from "sequelize-typescript";
import { ERROR } from "../common/result"


@Table({
  tableName: "t_b_user",
})
export default class User extends Model<User> {
 
  @Column({
    primaryKey: true,
  })
  uname !: string;
  @Column
  pwd !: string; 


  @Column
  roleId: string = 'admin';

  @Column
  departmentId: number = 0;

  
 

  checkpassword(pwd: string): boolean {
    return pwd === this.pwd
  }
  resetPwd(old: string, newpwd: string): number {
    if (this.checkpassword(old)) {
      this.pwd = newpwd;
      this.save();
      return 0;
    } else {
      return ERROR.PASSWORD;
    }
  }
}
export{
  User
}